package com.bigevent.service.impl;

import com.bigevent.mapper.CategoryMapper;
import com.bigevent.pojo.Category;
import com.bigevent.service.CategoryService;
import com.bigevent.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    public void addCategory(Category category) {
        //完善为提价的属性值
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());
        Map<String,Object> map = ThreadLocalUtil.get();
        category.setCreateUser((Integer)map.get("id"));
        categoryMapper.addCategory(category);
    }

    @Override
    public List<Category> categoryList() {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer userID = (Integer) map.get("id");
        return categoryMapper.categoryList(userID);
    }

    @Override
    public Category findCategoryByName(String categoryName) {
        return categoryMapper.findCategoryByName(categoryName);
    }

    @Override
    public Category detail(Integer id) {
        return categoryMapper.detail(id);
    }

    @Override
    public void updateCategory(Category category) {
        category.setUpdateTime(LocalDateTime.now());
        categoryMapper.updateCategory(category);
    }

    @Override
    public void deleteCategory(Integer id) {
        categoryMapper.deleteCategory(id);
    }


}
